package com.timi_licai.timi_licai_account.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.timi_licai.timi_licai_account.R;

import java.util.List;

/**
 * Created by LGH on 2015/3/16.
 */
public class AddCategoryCommonAdapter extends BaseAdapter {
    private Context context;
    private List<String> nameList;
    private List<Integer> ImageRes;

    public AddCategoryCommonAdapter (Context context, List<String> nameList, List<Integer> imageRes) {
        this.context = context;
        this.nameList = nameList;
        ImageRes = imageRes;
    }

    @Override
    public int getCount () {
        return nameList.size();
    }

    @Override
    public Object getItem (int position) {
        return nameList.get(position);
    }

    @Override
    public long getItemId (int position) {
        return position;
    }

    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_add_category, parent, false);
            viewHolder.ImageIcon = (ImageView) convertView.findViewById(R.id.item_add_category_image);
            viewHolder.txtName = (TextView) convertView.findViewById(R.id.item_add_category_name);
            viewHolder.txtEdit = (TextView) convertView.findViewById(R.id.item_add_category_editName);
            viewHolder.ImageChoice = (ImageView) convertView.findViewById(R.id.item_add_category_choice);
            convertView.setTag(viewHolder);
        } else {
            viewHolder=(ViewHolder)convertView.getTag();
        }
        viewHolder.ImageIcon.setImageResource(R.drawable.type_big_1);
        viewHolder.txtName.setText(nameList.get(position).toString());
        viewHolder.txtEdit.setText("编辑");
        viewHolder.ImageChoice.setImageResource(R.drawable.type_big_1);

        return convertView;
    }

    private class ViewHolder{
        public ImageView ImageIcon;
        public TextView txtName;
        public TextView txtEdit;
        public ImageView ImageChoice;
    }
}
